/**
 * Copyright (c) 2011 Tomi Paananen.
 *
 * Part of Quick Gestures engine library.
 */

// Own header
#include "gesturedatahelper.h"

// qgengine includes
#include "qgutils.h"
#include "qgtrace.h"


/*!
  \class GestureDataHelper
  \brief A helper class for resolving and holding gesture meta data.
*/


/*!
  Constructor.
*/
GestureDataHelper::GestureDataHelper()
    : m_pointCount(0),
      m_minX(0),
      m_minY(0),
      m_maxX(0),
      m_maxY(0),
      m_greaterSideLength(0)
{
}


/*!
  Constructor. For convenience.
*/
GestureDataHelper::GestureDataHelper(const Gesture &gesture)
    : m_pointCount(0),
      m_minX(0),
      m_minY(0),
      m_maxX(0),
      m_maxY(0),
      m_greaterSideLength(0)
{
    setGesture(gesture);
}


/*!
  Destructor.
*/
GestureDataHelper::~GestureDataHelper()
{
}


/*!
  Extracts the values from \a gesture.
*/
void GestureDataHelper::setGesture(const Gesture &gesture)
{
    extractValues(gesture);
}


/*!
  Returns the point count.
*/
int GestureDataHelper::pointCount()
{
    return m_pointCount;
}


/*!
  Returns the minimum X coordinate value.
*/
int GestureDataHelper::minX()
{
    return m_minX;
}


/*!
  Returns the minimum Y value.
*/
int GestureDataHelper::minY()
{
    return m_minY;
}


/*!
  Returns the maximum X coordinate value.
*/
int GestureDataHelper::maxX()
{
    return m_maxX;
}


/*!
  Returns the maximum Y coordinate value.
*/
int GestureDataHelper::maxY()
{
    return m_maxY;
}


/*!
  Returns the length of the greater side.
*/
int GestureDataHelper::greaterSideLength()
{
    return m_greaterSideLength;
}


/*!
  Extracts the values from \a gesture.
*/
void GestureDataHelper::extractValues(const Gesture &gesture)
{
    m_pointCount = gesture.points().count();

    if (m_pointCount < 2) {
        m_minX = 0;
        m_minY = 0;
        m_maxX = 0;
        m_maxY = 0;
        m_greaterSideLength = 0;
    }
    else {
        QGUtils::getMinMaxXY(gesture.points(), m_minX, m_minY, m_maxX, m_maxY);

        m_greaterSideLength = m_maxX - m_minX >= m_maxY - m_minY ?
                m_maxX - m_minX : m_maxY - m_minY;
    }

    /*DEBUG_INFO(m_pointCount << m_minX << m_minY << m_maxX << m_maxY
               << m_greaterSideLength);*/
}


// End of file.
